<?php
/*
  $menu = Blyn::app()->getAppUI()->getMenu('leftMenu');
  $workingMenus = Blyn::app()->getAppUI()->menus[BUIApp::Menu_WorkingSpacesLinks];
  $followingMenus = Blyn::app()->getAppUI()->menus[BUIApp::Menu_FollowingSpacesLinks];
 * 
 */

$appLinks = Blyn::app()->getAppUI()->getLinks();
$workingMenus = $appLinks['workingSpaceLinks'];
$followingMenus = $appLinks['followingSpaceLinks'];
$adminSpaceLinks = $appLinks['adminSpaceLinks'];

foreach ($adminSpaceLinks as $spaceId => $value) {
    $workingMenus[$spaceId] = $value;
}

//$currentApp = Blyn::app()->getActiveApp()->getUIManager();
$currentScreen = Blyn::app()->getUIManager()->getCurrentScreen();

$workingStr = Yii::t('site','Working');
$followingSpacesStr = Yii::t('site','Following');
$mostVisitStr = Yii::t('site','Most Visits');
/* define link of "working" and "following" for Space box */
//$workingTabLink = $currentScreen->getUrl(array('ajaxLink' => array('id' => 'workingLink', 'name' => 'Working')));
//$workingTabLink = $currentScreen->getAjaxLink("Working");
$workingTabLink = $control->getAjaxLink($workingStr);
//$workingTabLink = $currentScreen->getAjaxLink("Working",array('ajaxContainer'=>"show_userSpaceList_content",'ajaxView'=>'UserSpaceList'));
//$followingTabLink = $currentScreen->getUrl(array('ajaxLink' => array('id' => 'followingLink', 'name' => 'Following')));
//$followingTabLink = $currentScreen->getAjaxLink('Following');
$followingTabLink = $control->getAjaxLink($followingSpacesStr);
//$followingTabLink = $currentScreen->getAjaxLink('Following',array('ajaxContainer'=>"show_userSpaceList_content",'ajaxView'=>'UserSpaceList'));
//$visitTabLink = $currentScreen->getUrl(array('ajaxLink' => array('id' => 'visitLink', 'name' => 'Most Visits')));
//$visitTabLink = $currentScreen->getAjaxLink('Most Visits');
$visitTabLink = $control->getAjaxLink($mostVisitStr);
//$visitTabLink = $currentScreen->getAjaxLink('Most Visits', array('ajaxContainer' => "show_userSpaceList_content", 'ajaxView' => 'UserSpaceList'));

$spaceTabLinks = array();
//by default, set most visits tab as active
$spaceTabLinks['visits'] = array('ajaxUrl' => $visitTabLink, 'active' => 'active');
$spaceTabLinks['working'] = array('ajaxUrl' => $workingTabLink, 'active' => '');
$spaceTabLinks['following'] = array('ajaxUrl' => $followingTabLink, 'active' => '');


if ($control->isAjaxLinkClicked($mostVisitStr)) {
    $spaceTabLinks['visits']['active'] = 'active';
}

if ($control->isAjaxLinkClicked($workingStr)) {
    $spaceTabLinks['working']['active'] = 'active';
    $spaceTabLinks['visits']['active'] = '';
}

if ($control->isAjaxLinkClicked($followingSpacesStr)) {
    $spaceTabLinks['following']['active'] = 'active';
    $spaceTabLinks['visits']['active'] = '';
}
?>
<div><h4><?php echo Yii::t('site','Spaces:');?></h4></div>
<div class="workflow-box" style="padding: 0px">                
    <div style="padding: 8px 8px 8px 6px;background-color: #F5F5F5;height: 29px;border: 1px solid #ccc;">                
        <ul class="nav nav-tabs">
            <?php foreach ($spaceTabLinks as $link) { ?>
                <li class="<?php echo $link['active']; ?>">
                    <?php echo $link['ajaxUrl']; ?>
                </li>
            <?php } ?>                        
        </ul>
    </div>
    <div style="min-height: 200px;padding-top: 20px;padding-left: 5px">
        <ul class="nav nav-list">
            <?php
            if ($spaceTabLinks['working']['active'] == 'active') {
                foreach ($workingMenus as $link) {
                    ?>
                    <li>
                        <?php echo $link['ajaxUrl']; ?>
                    </li>
                    <?php
                }
            }
            ?>
            <?php
            if ($spaceTabLinks['following']['active'] == 'active') {
                foreach ($followingMenus as $link) {
                    ?>
                    <li>
                        <?php echo $link['ajaxUrl']; ?>
                    </li>
                    <?php
                }
            }
            ?>
            <?php if ($spaceTabLinks['visits']['active'] == 'active') { ?>
                <li class="nav-header"><?php echo Yii::t('site','Working Spaces');?></li>
                <?php
                foreach ($workingMenus as $link) {
                    ?>
                    <li>
                        <?php echo $link['ajaxUrl']; ?>
                    </li>
                    <?php
                }
                ?>
                <li class="nav-header"><?php echo Yii::t('site','Following Spaces');?></li>     
                    <?php foreach ($followingMenus as $link) {
                        ?>
                    <li>
                        <?php echo $link['ajaxUrl']; ?>
                    </li>
                    <?php
                }
            }
            ?>
        </ul>

    </div>
</div>
